{extend name='base' /}
{block name='content'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">文章管理</a>
        <a>
          <cite>文章列表</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
  <div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" method="get">
      <input type="text" name="title" placeholder="请输入文章标题" autocomplete="off" class="layui-input" value="<?php echo $title = isset($_GET['title'])?$_GET['title']:'';?>">
      <?php  $cateid = isset($_GET['cateid'])?$_GET['cateid']:'';?>
      <div class="layui-input-inline " style="margin-top: -1px">
        <select name="cateid" >
          <option value="">请选择栏目</option>
          {volist name = 'CateData' id='vo'}
          <option value="{$vo.cate_id}" {if $cateid == $vo['cate_id']}selected{/if}>{$vo.cate_name}</option>
          {/volist}
        </select>
      </div>
      <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
    </form>

  </div>
  <xblock>
    <button class="layui-btn" onclick="x_admin_show('添加文章','{:url('article/add')}')"><i class="layui-icon"></i>添加
    </button>
  </xblock>
  <table class="layui-table">
    <thead>
    <tr>

      <th>ID</th>
      <th>文章标题</th>
      <th>文章类别</th>
      <th>添加时间</th>
      <th>更改时间</th>
      <th>状态</th>
      <th>操作</th>
    </thead>
    <tbody>
{volist name='articleData' id='vo'}
    <tr>
      <td>{$vo.article_id}</td>
      <td>{$vo.title}</td>
      <td>
        {$vo.cate_name}
      </td>
      <td>{$vo.create_time}</td>
      <td>{$vo.update_time}</td>
      <td class="td-status">
        {if $vo.status==1}
        <span class="layui-btn layui-btn-normal layui-btn-xs">显示</span>
        {else /}
        <span class="layui-btn layui-btn-danger layui-btn-xs">不显示</span>
        {/if}
      </td>
      <td class="td-manage">
        <div class="layui-btn-group">
          {if $vo.status==1}
          <a onclick="member_stop(this,{$vo.article_id})" href="javascript:;" class="layui-btn layui-btn-warm layui-btn-xs" stu="{$vo.status}">不显示</a>
          {else /}
          <a onclick="member_stop(this,{$vo.article_id})" href="javascript:;" class="layui-btn layui-btn-info layui-btn-xs" stu="{$vo.status}">显示</a>
          {/if}
          <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs" onclick=" x_admin_show('编辑','{:url('article/edit','id='.$vo['article_id'])}')">编辑</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="member_del(this,{$vo.article_id})" href="javascript:;">永久删除</a>
          <a class="layui-btn layui-btn-warm layui-btn-xs" onclick="del(this,{$vo.article_id})" href="javascript:;">删除到回收站</a>
        </div>
      </td>
    </tr>
{/volist}
    </tbody>
  </table>
  <div class="page">
    <div>

    </div>
  </div>

</div>
<script>

    /*用户-停用*/
    function member_stop(obj,id){
            var sta = $(obj).attr('stu');
            if (sta==1){
                var str ='确认要不显示吗？'
            } else{
                var str ='确认要显示吗？'
            }
            layer.confirm(str, function (index) {
                $.ajax({
                    url:"{:url('article/upSta')}",
                    type:'post',
                    dataType:'json',
                    data:{id:id,sta:sta},
                    success:function (res) {
                        if (res.code) {
                            layer.msg(res.message, {icon: 6, time: 1000});
                            setTimeout(function () {
                                window.location.reload();
                            },1000)

                        } else {
                            layer.msg(res.message, {icon: 2, time: 1000})
                        }
                    },
                    error:function () {
                        layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                    }
                })


            });
    }

    /*用户-删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？', function (index) {
            // //发异步删除数据
            $.ajax({
                url: "{:url('article/del')}",
                data: {id: id},
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code) {
                        $(obj).parents("tr").remove();
                        layer.msg(res.message, {icon: 6, time: 1000});
                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error: function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })

        });
    }

    function del(obj,id) {
        layer.confirm('确认要删除吗？', function (index) {
            // //发异步删除数据
            $.ajax({
                url: "{:url('article/delrecycle')}",
                data: {id: id},
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code) {
                        $(obj).parents("tr").remove();
                        layer.msg(res.message, {icon: 6, time: 1000});
                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error: function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })

        });
    }



</script>

</body>
{/block}